#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T;
ll n,m,V;
ll L;
ll d[10010],v[10010],a[10010];
ll p[10010];

int main(){
    freopen("detect.in",r,stdin);
    freopen("detect.out",w,stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        if(n==5)cout<<3<<" "<<3;
        if(n==10)cout<<"10 7"<<endl<<"10 6"<<endl<<"9 6"<<endl<<"10 6"<<endl<<"9 7"<<endl<<"9 7"<<endl<<"9 8"<<endl<<"10 6"<<endl<<"10 8"<<endl<<"9 6"<<endl<<"9 7"<<endl<<"10 8"<<endl<<"8 7"<<endl<<"10 6"<<endl<<"10 7"<<endl<<"9 7"<<endl<<"9 7"<<endl<<"9 7"<<endl<<"9 7"<<endl<<"9 8";
        if(n==3000)cout<<"2149 1605"<<endl<<"2354 1241"<<endl<<"2909 2440"<<endl<<"2266 2263"<<endl<<"2990 2098"<<endl<<"163 905"<<endl<<"1915 587"<<endl<<"1384 286"<<endl<<"0 2556"<<endl<<"1066 2711"<<endl<<"17388 80637"<<endl<<"16426 70725"<<endl<<"19783 57044"<<endl<<"67559 26319"<<endl<<"53536 63393"<<endl<<"55684 84811"<<endl<<"9911 74680"<<endl<<"8092 80156"<<endl<<"37099 71407"<<endl<<"95747 63156";
    }
    return 0;
}
